import { reactive } from "vue";
import axios from "axios";

const useRequest = (url: string) => {
  const data = reactive({
    result: null,
    loading: true,
    loaded: false,
    error: null,
  });
  axios
    .get(url)
    .then((resp) => {
      data.result = resp.data.data.records;
      data.loaded = true;
    })
    .catch((e) => {
      data.error = e;
    })
    .finally(() => {
      data.loading = false;
      data.loaded = true;
    });

  return data;
};

export default useRequest;
